/**
 * 部门列表项
 */
interface DepartmentListItemResponse {
    /**
     * 标识符
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * 部门名称
     */
    name:string;
    /**
     * 权限数
     */
    authorizationCount: number;
    /**
     * 用户数
     */
    userCount: number;
    /**
     * 专员类型
     */
    types: string;

    typeList:string[]

    highAuthNumber:number[];
    middleAuthNumber:number[];
    lowAuthNumber:number[];
    secAuthorizationTypeTag:string[];
}

/**
 * 部门详情
 */
interface DepartmentDetailResponse extends BaseResponse {
    /**
     * 部门名称
     */
    name: string;
    /**
     * 权限值
     */
    roles: Array<string>;
    /**
     * 专员类型
     */
    types: Array<string>;
}
/**
 * 部门权限
 */
interface DepartmentAuth {
    //高等级权限
    HighAuthNumber:number[];
    //中等级权限
    MiddleAuthNumber:number[];
    //低等级权限
    LowAuthNumber:number[];
    //二级权限标签
    SecAuthTypeTag:string[]
}
/**
 * 部门服务
 */
interface IDepartmentService {

    /**
     * 获取列表
     * v1.0
     * @param name 部门名称
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(name: string, skip: number, count: number): ng.IHttpPromise<ListResponse<DepartmentListItemResponse>>;

    /**
     * 获取详细
     * v1.0
     * @param id 部门编号
     */
    getDetail(id: string): ng.IHttpPromise<DepartmentDetailResponse>;

    /**
     * 添加部门
     * v1.0
     * @param name 部门名称
     * @param roles 权限值
     * @param types 专员类型
     */
    add(name: string, roles: Array<string>, types: Array<string>): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑部门
     * v1.0
     * @param id 部门编号
     * @param name 部门名称
     * @param roles 权限值
     * @param types 专员类型
     */
    edit(id: string, name: string, roles: Array<string>, types: Array<string>): ng.IHttpPromise<BaseResponse>;

    /**
     * 删除部门
     * v1.0
     * @param id 部门编号
     */
    delete(id: string): ng.IHttpPromise<BaseResponse>;


    editAuth:(id:string,body:DepartmentAuth)=>ng.IHttpPromise<BaseResponse>;
}


class departmentService implements IDepartmentService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(name: string, skip: number, count: number): ng.IHttpPromise<ListResponse<DepartmentListItemResponse>> {
        return this.http<ListResponse<DepartmentListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("department?name={{name}}&skip={{skip}}&count={{count}}", {
                name: name,
                skip: skip,
                count: count
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<DepartmentDetailResponse> {
        return this.http<DepartmentDetailResponse>({
            method: "GET",
            url: this.route.getUrl("department/{{id}}", {
                id: id
            })
        });
    }

    add(name: string, roles: Array<string>, types: Array<string>): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("department"),
            data: {
                name: name,
                roles: roles,
                types: types
            }
        });
    }

    edit(id: string, name: string, roles: Array<string>, types: Array<string>): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("department/{{id}}", {
                id: id
            }),
            data: {
                name: name,
                roles: roles,
                types: types
            }
        });
    }

    delete(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("department/{{id}}", {
                id: id
            })
        });
    }
    editAuth(id:string,body:DepartmentAuth):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"PUT",
            url:this.route.getUrl("department/SaveDepartmentAuth?id={{id}}",{id:id}),
            data:body
        })
    }
}

angular.module('departmentService',[]).service("departmentService",['$http','routeService',departmentService]);